#ifndef XM_EVLOOPTHREAD_HH
#define XM_EVLOOPTHREAD_HH

#include <functional>
#include <mutex>
#include <condition_variable>
#include <string>

#include "XM_noncopyable.hh"
#include "XM_Thread.hh"
#include "pch.hh"

XM_NAMESPACE_BEGIN

struct EvLoop;

struct EvLoopThread : private XM_noncopyable
{
    using ThreadInitCallback = std::function<void(EvLoop*)>;

    EvLoopThread(const ThreadInitCallback& cb = ThreadInitCallback(),
                 const std::string& name = std::string());
    
    ~EvLoopThread();

    EvLoop* startLoop();

private:
    void threadFunc();

    EvLoop* loop__;
    bool is_exiting__;
    Thread thread__;
    std::mutex mtx__;
    std::condition_variable cond__;
    ThreadInitCallback callback__;
};

XM_NAMESPACE_END

#endif // header file protect